<template>
    <div>
        <CityHeader></CityHeader>
        <CitySearch :cities="cities"></CitySearch>
        <CityList 
        :cities="cities" 
        :hot="hotCities"
        :letter="letter"></CityList>
        <CityAlphabet :cities="cities"
            @change="handleLetterChang">
            <!-- 监听名字为change的事件 -->
        </CityAlphabet>
    </div>
</template>


<script>
import axios from 'axios'
import CityHeader from './components/Header'
import CitySearch from './components/Search'
import CityList from './components/List'
import CityAlphabet from './components/Alphabet'
export default {
    name: 'City',
    components:{
        CityHeader,CitySearch,
        CityList,CityAlphabet
    },
    data(){
        return {
            cities:{},//存放abcd首字母所对应的城市的名字
            hotCities:[],//存放热门城市
            letter:''
        }
    },
    methods:{
        getCityInfo(){
            axios.get("/api/city.json").then(this.handleGetCityInfoSucc)
        },
        handleGetCityInfoSucc(res){
            res= res.data
            if(res.ret && res.data){
                const data = res.data
                this.cities = data.cities
                this.hotCities = data.hotCities
            }
        },
        handleLetterChang(letter){
            console.log(letter)
            this.letter = letter
        }
    },
    created(){
        //将html元素的touchmove事件去除，这样拖动页面的时候顶部不会出现空白
        document.body.addEventListener('touchmove', function(e) {
            if(e._isScroller) return;
            // 阻止默认事件
                e.preventDefault();
            }, {
                passive: false
            });
        },
    mounted(){
        this.getCityInfo()
    }
}   

</script>

<style lang="stylus" scoped>
    
</style>
